<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../static/plugin/layui/css/layui.css">
    <link rel="stylesheet" href="../static/css/login.css">
</head>
<body class="beg-login-bg">
<div class="beg-login-box">
    <header>
        <h1>后台登录</h1>
    </header>
    <div class="beg-login-main layui-form">
        <div class="layui-form-item">
            <label class="beg-login-icon">
                <i class="layui-icon">&#xe612;</i>
            </label>
            <input type="text" name="loginName" lay-verify="loginName" autocomplete="off" placeholder="这里输入登录名"
                   class="layui-input">
        </div>
        <div class="layui-form-item">
            <label class="beg-login-icon">
                <i class="layui-icon">&#xe642;</i>
            </label>
            <input type="password" name="password" lay-verify="password" autocomplete="off" placeholder="这里输入密码"
                   class="layui-input">
        </div>
        <div class="layui-form-item">
            <div class="beg-pull-left beg-login-remember">
                <label>记住帐号？</label>
                <input type="checkbox" name="rememberMe" value="true" lay-skin="switch" title="记住帐号">
            </div>
            <div class="beg-pull-right">
                <button class="layui-btn layui-btn-primary" lay-submit lay-filter="login">
                    <i class="layui-icon">&#xe650;</i> 登录
                </button>
            </div>
            <div class="beg-clear"></div>
        </div>
    </div>
</div>
</div>
<script src="../static/js/jquery.js"></script>
<script src="../static/plugin/layui/layui.js"></script>
<script src="../static/js/common.js"></script>
<script type="text/javascript">
    layui.use(['layer', 'element', 'form'], function () {
        var layer = layui.layer;
        var element = layui.element;
        var form = layui.form;

        form.on('submit(login)', function (data) {
            console.log(data);
            $.ajax({
                url: '/persional/account/login',
                type: 'POST',
                contentType: "application/x-www-form-urlencoded",
//                data: {'loginName':data.field.loginName,'password':data.field.password,'rememberMe':data.field.rememberMe},
                data: data.field,
                success: function (res) {
                    if (res.errcode) {
                        layui.data('user', {
                            key:'id',
                            value:res.data.id
                        });
                        layui.data('user', {
                            key:'loginName',
                            value:res.data.loginName
                        });
                        layui.data('user', {
                            key:'departmentName',
                            value:res.data.departmentName
                        });
                        layui.data('user', {
                            key:'name',
                            value:res.data.userInfo.name
                        });
                        layui.data('user', {
                            key:'avator',
                            value:res.data.userInfo.avator
                        });
                        console.log(layui.data('user'));
                        parent.location.href = base_url + '/index.html';
                    } else {
                        layer.msg(res.errmsg, {icon: 2});
                    }
                },
                error: function (data) {
                    layer.msg('网络错误', {icon: 2});
                }
            })
            return false;
        });
    })
</script>
</body>
</html>